#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

int ans,tag[N],fl,cnt,fa[22][N],dep[N],dis[N],n,m,maxw,dfn[N],tim,to[N],ind[N];
struct tra{int u,v,lca,dis;}tr[N];
vector<pii> G[N];

void dfs(int x,int p){
	fa[0][x] = p; dep[x] = dep[p]+1; dfn[x] = ++tim; ind[tim] = x;
	for(pii d : G[x]){
		if(d.fi == p) continue; dis[d.fi] = dis[x] + d.se;  dfs(d.fi,x); to[dfn[d.fi]] = d.se;
	}
}

bool check(int x){
	for(int i = 1;i <= n;i++) tag[i] = 0;ans = 0,cnt = 0,fl = 0;
	for(int i = 1;i <= m;i++){
		if(tr[i].dis <= x) continue; ans = max(ans,tr[i].dis - x);
		tag[dfn[tr[i].u]]++; tag[dfn[tr[i].v]]++; tag[dfn[tr[i].lca]]-=2;cnt++;
	}
	for(int i = n;i >= 1;i--) tag[dfn[fa[0][ind[i]]]] += tag[i];
	for(int i = 2;i <= n;i++) if(tag[i] == cnt && to[i] >= ans) {fl = 1;break;}
	return fl;
}

int lca(int x,int y){if(dep[x] < dep[y]) swap(x,y); for(int i = 20;~i;i--) if(dep[fa[i][x]] >= dep[y]) x = fa[i][x]; if(x == y) return x;for(int i = 20;~i;i--) if(fa[i][x] != fa[i][y]) x = fa[i][x],y = fa[i][y];return fa[0][x];}

int dist(int x,int y){return dis[x] + dis[y] - 2 * dis[lca(x,y)];}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i < n;i++){
		int u = in,v = in,w = in; maxw += w;
		G[u].pb(pii(v,w)); G[v].pb(pii(u,w));
	}
	dfs(1,0);
	for(int i = 1;i <= 20;i++)
		for(int j = 1;j <= n;j++)
			fa[i][j] = fa[i-1][fa[i-1][j]];
	
	for(int i = 1;i <= m;i++){
		tr[i].u = in,tr[i].v = in; tr[i].dis = dist(tr[i].u,tr[i].v); tr[i].lca = lca(tr[i].u,tr[i].v);
	}
	int l = 0,r = 300000000;
	while(l <= r){
		int mid = l + r >> 1;
		if(check(mid)) r = mid-1;
		else l = mid+1;
	}
	printf("%d\n",l);
	return 0;
}

